char val; int times = 3; #define LED 25 // the setup function runs once when you press reset or power the board void setup() { // initialize digital pin LED_BUILTIN as an output. pinMode(LED, OUTPUT); Serial.begin(9600); //initiate serial communication at 9600 baud/sec } void loop(){ if (Serial.available() >0) { val = Serial.read(); //create 'character' datatype variable 'val' if (val == 'b'){ //if 'b' received over serial BlinkLED(); } else if (val == '0'){ digitalWrite(LED,LOW); //turn LED OFF } } } void BlinkLED(){ while(times--) { digitalWrite(LED,HIGH); //turn LED ON delay(200); digitalWrite(LED,LOW); //turn LED OFF delay(200); } times = 3; }